package com.hejing.bpeldesign.bpelprase;

import com.hejing.bpeldesign.model.BpelNode;
import org.w3c.dom.Element;

import java.util.HashMap;
import java.util.Map;

public class BpelNodeFactory {
    private static final Map<String, NodeParserStrategy> STRATEGY_MAP = new HashMap<>();
    private static final NodeParserStrategy DEFAULT_STRATEGY = new DefaultParser();

    static {
        register("invokebean", new InvokeNodeParser());
        register("invokewf", new InvokeNodeParser());
        register("invoke", new InvokeNodeParser());
        register("expression", new ExpressionNodeParser());
        register("case", new CaseNodeParser());
        register("receive", new ReceiveNodeParser());
        register("throw", new ThrowNodeParser());
        // ... 更多注册
    }

    public static void register(String tagName, NodeParserStrategy strategy) {
        STRATEGY_MAP.put(tagName.toLowerCase(), strategy);
    }

    public static BpelNode parse(Element el) {
        String tag = el.getTagName().toLowerCase();
        NodeParserStrategy strategy = STRATEGY_MAP.getOrDefault(tag, DEFAULT_STRATEGY);
        return strategy.parse(el);
    }
}
